/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function carregaDiv(div, getURL, form)
{
    if (getURL.indexOf('?') != -1)
    {
        getURL = getURL + '&nomeProc=' + form.nomeProc.value;
    }
    else
    {
        getURL = getURL + '?nomeProc=' + form.nomeProc.value;
    }

    if (form.name == 'listaEstab')
    {
      getURL = getURL + '&cnpjProc=' + form.cnpjProc.value;
    }
    if (form.name == 'listaAut')
    {
      getURL = getURL + '&cpfProc=' + form.cpfProc.value;
    }
    else if (form.name == 'listaPac' || form.name == 'pesquisaPac')
    {
      getURL = getURL + '&cpfProc=' + form.cpfProc.value;
    }

    if (form.name == 'listaPac' || form.name == 'pesquisaPac')
    {
        Radio= form.sexoProc;
        for(var i=0;i<Radio.length;i++) {
            if(Radio[i].checked) {
                    getURL = getURL + '&sexoProc=' + Radio[i].value;
            }
        }
    }
    
    carregaAjax(div, getURL);
}

function excluirForm(div, getURL, form)
{
//    getURL = getURL + '?acao=' + action;
    var postParams, itens;
    
    itens = form.itensParaRemover.value;
    
    while (itens.indexOf("..") != -1)
    {
      itens = itens.replace("..", ",");
    }
    
    while (itens.indexOf(".") != -1)
    {
      itens = itens.replace(".", "");
    }
    
    postParams = 'acao=' + encodeURI(form.acao.value);
    postParams = postParams + '&itensParaRemover=' + encodeURI(itens);
    
    carregaAjaxViaPOST(div, getURL, postParams);
}

function saveForm(div, getURL, form)
{
//    getURL = getURL + '?acao=' + action;
    var postParams;
    
    if (form.name == 'cadClie')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&pacId=' + encodeURI(form.pacId.value);
        postParams = postParams + '&nome=' + encodeURI(form.nome.value);
        postParams = postParams + '&cpf=' + encodeURI(form.cpf.value);
        postParams = postParams + '&listCidades=' + encodeURI(form.listCidades.value);
        postParams = postParams + '&estadoCivil=' + encodeURI(form.estadoCivil.value);
        postParams = postParams + '&sexo=' + encodeURI(form.sexo.value);
        postParams = postParams + '&possuiConvenio=' + encodeURI(form.possuiConvenio.value);
        postParams = postParams + '&querVisita=' + encodeURI(form.querVisita.value);
        postParams = postParams + '&email=' + encodeURI(form.email.value);
        postParams = postParams + '&fone=' + encodeURI(form.fone.value);
        postParams = postParams + '&cep=' + encodeURI(form.cep.value);
        postParams = postParams + '&ende=' + encodeURI(form.ende.value);
        postParams = postParams + '&dataNasc=' + encodeURI(form.dataNasc.value);
        postParams = postParams + '&numFilhos=' + encodeURI(form.numFilhos.value);
        postParams = postParams + '&idadeFilhos=' + encodeURI(form.idadeFilhos.value);
        postParams = postParams + '&localTrabPac=' + encodeURI(form.localTrabPac.value);
        postParams = postParams + '&nomeConjuge=' + encodeURI(form.nomeConjuge.value);
        postParams = postParams + '&localTrabConj=' + encodeURI(form.localTrabConj.value);
        postParams = postParams + '&tipoCA=' + encodeURI(form.tipoCA.value);
        postParams = postParams + '&nomeMedico=' + encodeURI(form.nomeMedico.value);
        postParams = postParams + '&hospital=' + encodeURI(form.hospital.value);
        postParams = postParams + '&pessoaAutorizada=' + encodeURI(form.pessoaAutorizada.value);
        postParams = postParams + '&obs=' + encodeURI(form.obs.value);
        postParams = postParams + '&dataFalec=' + encodeURI(form.dataFalec.value);
        postParams = postParams + '&ativo=' + encodeURI(form.ativo.value);
    }
    else if (form.name == 'cadEstab')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&estabId=' + encodeURI(form.estabId.value);
        postParams = postParams + '&nomeFantasia=' + encodeURI(form.nomeFantasia.value);
        postParams = postParams + '&razaoSocial=' + encodeURI(form.razaoSocial.value);
        postParams = postParams + '&cnpj=' + encodeURI(form.cnpj.value);
        postParams = postParams + '&fone=' + encodeURI(form.fone.value);
        postParams = postParams + '&listCidades=' + encodeURI(form.listCidades.value);
        postParams = postParams + '&ende=' + encodeURI(form.ende.value);
        postParams = postParams + '&cep=' + encodeURI(form.cep.value);
        postParams = postParams + '&email=' + encodeURI(form.email.value);
        postParams = postParams + '&obs=' + encodeURI(form.obs.value);
    }
    else if (form.name == 'cadDesp')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&despId=' + encodeURI(form.despId.value);
        postParams = postParams + '&idEstab=' + encodeURI(form.idEstab.value);
        postParams = postParams + '&idPac=' + encodeURI(form.idPac.value);
        postParams = postParams + '&idTipoDesp=' + encodeURI(form.idTipoDesp.value);
        postParams = postParams + '&dataDesp=' + encodeURI(form.dataDesp.value);
        postParams = postParams + '&valorDesp=' + encodeURI(form.valorDesp.value);
        postParams = postParams + '&obs=' + encodeURI(form.obs.value);
    }
    else if (form.name == 'cadTipoDesp')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&tipoDespId=' + encodeURI(form.tipoDespId.value);
        postParams = postParams + '&descricao=' + encodeURI(form.descricao.value);
        postParams = postParams + '&obs=' + encodeURI(form.obs.value);
    }
    else if (form.name == 'cadRec')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&recId=' + encodeURI(form.recId.value);
        postParams = postParams + '&idPac=' + encodeURI(form.idPac.value);
        postParams = postParams + '&idDesp=' + encodeURI(form.idDesp.value);
        postParams = postParams + '&dataRec=' + encodeURI(form.dataRec.value);
        postParams = postParams + '&valorDesp=' + encodeURI(form.valorDesp.value);
        postParams = postParams + '&obs=' + encodeURI(form.obs.value);
    }
    else if (form.name == 'cadAut')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&autId=' + encodeURI(form.autId.value);
        postParams = postParams + '&idPac=' + encodeURI(form.idPac.value);
        postParams = postParams + '&idEstab=' + encodeURI(form.idEstab.value);
        postParams = postParams + '&dataAut=' + encodeURI(form.dataAut.value);
        postParams = postParams + '&descricao=' + encodeURI(form.descricao.value);
    }
    else if (form.name == 'bdInstall')
    {
        postParams = 'acao=' + encodeURI(form.acao.value);
        postParams = postParams + '&user=' + encodeURI(form.user.value);
        postParams = postParams + '&pwd=' + encodeURI(form.pwd.value);
        postParams = postParams + '&server=' + encodeURI(form.server.value);
    }

    carregaAjaxViaPOST(div, getURL, postParams);
}

function addRemItem(value, form)
{
    var str = form.itensParaRemover.value;
    
    if (str.indexOf(value) != -1)
        str = str.replace(value, ""); //substitui o valor procurado por vazio. "remove o valor".
    else
        str = str.concat(value); //adiciona novo valor.
    
//    alert("clie id: "+str);
    
    form.itensParaRemover.value = str;
}

function addRemConv(value, form)
{
    var str = form.possuiConvenio.value;
    
    if (str.indexOf(value) != -1)
        str = str.replace(value, ""); //substitui o valor procurado por vazio. "remove o valor".
    else
        str = str.concat(value); //adiciona novo valor.
    
//    alert("Str: " + str);
    
    form.possuiConvenio.value = str;
}

function muda_ativo(form){
  if (form.ativo.value == "S") 
    form.ativo.value = "N";
  else
    form.ativo.value = "S";
}

function muda_sexo(form, sValue){
  form.sexo.value = sValue;
}

function muda_estadoCivil(form, sValue){
  form.estadoCivil.value = sValue;
}

function muda_visita(form, sValue){
  form.querVisita.value = sValue;
}
